/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.ClassReportMapper;
import cn.qidisoft.edu.hzjt.model.ClassReport;
import cn.qidisoft.edu.hzjt.service.IClassReportService;

/**
 * 
 * 
 * @author Administrator
 * @version $Id: CatalogServiceImpl.java, v 0.1 2018年9月28日 上午9:17:27 Administrator hhl $
 */
@Service("classReportService")
public class ClassReportServiceImpl implements IClassReportService {
    @Autowired
    private ClassReportMapper classReportMapper;

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryList(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public List<ClassReport> queryList(ClassReport classReport) {
        try {
            return classReportMapper.queryList(classReport);

        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryByPK(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public ClassReport queryByPK(ClassReport classReport) {
        try {
            return classReportMapper.queryByPK(classReport);

        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#add(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void add(ClassReport classReport) {
        try {
            classReportMapper.add(classReport);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#update(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void update(ClassReport classReport) {
        try {
            classReportMapper.update(classReport);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#delete(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    @Transactional
    public void delete(ClassReport classReport) {
        try {
            classReportMapper.delete(classReport);
        } catch (Exception e) {
            throw new DBException(QdfRespCode.QDF_020004.getCode(), QdfRespCode.QDF_020004.getMsg(),
                e);
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#queryPageList(cn.qidisoft.microClass.resource.model.basis.Catalog, cn.qidisoft.core.common.pagination.Page)
     */
    @Override
    public PaginationBean<ClassReport> queryPageList(ClassReport classReport, Page page) {
        try {

            int c = classReportMapper.queryPageListcount(classReport);
            int totalRecords = 0;
            totalRecords = (int) c;

            PaginationBean<ClassReport> pageHolder = new PaginationBean<ClassReport>(page,
                totalRecords);

            List<ClassReport> resultList = classReportMapper.queryPageList(classReport,
                new RowBounds((pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(),
                    pageHolder.getPageSize()));
            pageHolder.setPageList(resultList);
            return pageHolder;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /** 
     * @see cn.qidisoft.microClass.resource.service.ICatalogService#validation(cn.qidisoft.microClass.resource.model.basis.Catalog)
     */
    @Override
    public int validation(ClassReport classReport) {
        try {
            return classReportMapper.validation(classReport);
        } catch (Exception e) {
            e.printStackTrace();
            return -99;
        }

    }

}
